home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_12_08 / treu / bgipixel.c < prev    next >
C/C++ Source or Header  |  1994-05-25  |  2KB  |  86 lines

  1. /*****************************************************
  2.  * BGIPIXEL.C - this is a compiler-specific function
  3.  * to examine and fill pixels.
  4.  *
  5.  * for TurboC V 2.0
  6.  *
  7.  * by Anton Treuenfels
  8.  * last revision:  04/11/94
  9.  *****************************************************/
  10.  
  11. #include "usrdef.h"
  12.  
  13. /*******************************
  14.  * Header Section - BGIPIXEL.C *
  15.  *******************************/
  16.  
  17. #ifndef SEEN_BGIPIX
  18. #define SEEN_BGIPIX
  19.  
  20. /* function prototype */
  21.  
  22. void checkflood(int, int, Boolean);
  23.  
  24. #endif
  25.  
  26. /*****************************
  27.  * Code Section - BGIPIXEL.C *
  28.  *****************************/
  29.  
  30. #include <stdio.h>
  31. #include <stdlib.h>
  32. #include <graphics.h>
  33.  
  34. #include "bgigrh.h"
  35. #include "flood.h"
  36. #include "uflood.h"
  37.  
  38. /* efficiency counts */
  39.  
  40. static long readcnt, writecnt;
  41.  
  42. /*****************************************************/
  43.  
  44. /* check and fill pixel */
  45.  
  46. static int bgipixel(int xpos, int ypos) {
  47.  
  48.     int pixval;
  49.  
  50.     readcnt++;
  51.     if ((ypos >= 0) && (ypos <= MaxYPos)
  52.         && (xpos >= 0) && (xpos <= MaxXPos)) {
  53.             pixval = getpixel(xpos, ypos);
  54.             if (pixval == 0) {
  55.                 writecnt++;
  56.                 if (xpos & 1)
  57.                     putpixel(xpos, ypos, MaxColor);
  58.                 return(TRUE);
  59.             }
  60.                 pixval = max(0, pixval - 1);
  61.                 putpixel(xpos, ypos, pixval);
  62.     }
  63.     return(FALSE);
  64. }
  65.  
  66. /* checking fill using Borland Graphics Interface */
  67.  
  68. void checkflood(int xpos, int ypos, Boolean fastfill) {
  69.  
  70.     char txtbuf[80];
  71.  
  72.     readcnt = writecnt = 0;
  73.     abspoint(&xpos, &ypos);
  74.     if (fastfill)
  75.         flood(xpos, ypos, bgipixel);
  76.     else
  77.         uflood(xpos, ypos, bgipixel);
  78.     sprintf(txtbuf, "Pixels read=    %ld", readcnt);
  79.     outtextxy(1, 1, txtbuf);
  80.     sprintf(txtbuf, "Pixels written= %ld", writecnt);
  81.     outtextxy(1, 10, txtbuf);
  82.     sprintf(txtbuf, "Write/Read= %.2f",
  83.          (float)writecnt / (float)readcnt);
  84.     outtextxy(1, 21, txtbuf);
  85. }
  86.